package com.yuju.account.dao.impl;


import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.yuju.account.dao.IAccountReportDao;
import com.yuju.account.dao.entity.AccountReport;
import com.yuju.account.dao.mapper.AccountReportMapper;
import com.yuju.account.model.AccountReportModel;
import com.yuju.account.model.GuestBalanceModel;
import com.yuju.common.PageModel;
import com.yuju.common.core.dao.AbstractBaseDao;
import com.yuju.persist.base.mapper.BaseMapper;

/**
 * 类名：AccountReportDaoImpl  <br />
 *
 * 功能：
 *
 * @author : jiaokn <br />
 * @Date : 2017年12月20日 下午5:58:00  <br />
 * @version : 1.1 <br />
 */
@Repository
public class AccountReportDaoImpl extends AbstractBaseDao<AccountReportModel, AccountReport, String> implements IAccountReportDao {
	
	@Autowired
	private AccountReportMapper accountReportMapper;
	
	@Override
	public BaseMapper<AccountReport, String> getMapper() {
		return accountReportMapper;
	}

	@Override
	public PageModel listOrderAndCount(AccountReportModel accountReportModel , Integer currentPage, Integer rows) {
		PageModel pageModel = new PageModel(currentPage, rows);
		Map<Object, Object> map = getBeanMap(accountReportModel,currentPage,rows);
		Integer total = countByMap(map);
		if (total == null || total == 0) {
			pageModel.setTotal(total);
			return pageModel;
		}
		pageModel.setTotal(total);
		List<AccountReport> list = accountReportMapper.listOrderAndCount(map);
		List<AccountReportModel> modelList = convertP2M(list);
		pageModel.setRows(modelList);
		return pageModel;
	}

	@Override
	public Integer countByMap(Map<Object, Object> map) {
		return accountReportMapper.countByMap(map);
	}

	@Override
	public PageModel listMemberOrderAndCount(AccountReportModel accountReportModel, Integer currentPage, Integer rows) {
		PageModel pageModel = new PageModel(currentPage, rows);
		Map<Object, Object> map = getBeanMap(accountReportModel,currentPage,rows);
		Integer total = countMemberByMap(map);
		if (total == null || total == 0) {
			pageModel.setTotal(total);
			return pageModel;
		}
		pageModel.setTotal(total);
		List<AccountReport> list = accountReportMapper.listMemberOrderAndCount(map);
		List<AccountReportModel> modelList = convertP2M(list);
		pageModel.setRows(modelList);
		return pageModel;
	}

	@Override
	public Integer countMemberByMap(Map<Object, Object> map) {
		return accountReportMapper.countMemberByMap(map);
	}

	@Override
	public List<GuestBalanceModel> guestBalanceReport(AccountReportModel accountReportModel) {
		return accountReportMapper.guestBalanceReport(getBeanMap(accountReportModel));
	}

	@Override
	public PageModel guestBalanceReportPage(AccountReportModel accountReportModel, Integer currentPage, Integer rows) {
		PageModel pageModel = new PageModel(currentPage, rows);
		Map<Object, Object> map = getBeanMap(accountReportModel,currentPage,rows);
		Integer total = countSum(map);
		if (total == null || total == 0) {
			return null;
		}
		pageModel.setTotal(total);
		List<GuestBalanceModel> list = accountReportMapper.guestBalanceReport(map);
		pageModel.setRows(list);
		return pageModel;
	}

	@Override
	public Integer countSum(Map<Object, Object> map) {
		return accountReportMapper.countSum(map);
	}

	@Override
	public GuestBalanceModel guestBalanceSumRpt(AccountReportModel accountReportModel) {
		return accountReportMapper.guestBalanceSumRpt(getBeanMap(accountReportModel));
	}
}
